import logging

import pytest

from resource.pom.contacts import Contacts
from resource.pom.keyboard import Keyboard
from resource.pom.mms import MMS


@pytest.fixture(autouse=True)
def preset_contactor(device):
    logging.info('方法前置----预置联系人')
    Contacts.create_contactor(device)
    yield
    logging.info('方法后置----删除联系人')
    Contacts.delete_contactor(device)


class Test:
    app = Contacts
    keyboard = Keyboard

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('步骤1.点击联系人应用')
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        logging.info('预期结果1.正常进入联系人应用内')
        device.assert_current_window(self.app.window_name)

        logging.info('步骤2、点击切换到联系人列表页')
        device.click(*self.app.menu_contacts)
        logging.info('预期结果2、成功切换到联系人列表页')
        device.refresh_layout()
        device.assert_text_exist(self.app.test_name)

        logging.info('步骤3、联系人列表中打开具体联系人，点击短信按钮')
        contact = device.get_element_by_text(self.app.test_name)
        device.click_element(contact)
        device.click(*self.app.mms_link)
        logging.info('预期结果3、成功跳转到短信编辑页面，且输入信息后可在短信应用中显示')
        device.assert_current_window(MMS.window_name)
        device.refresh_layout()
        device.assert_text_exist('新建信息')
        device.assert_type_exist('TextArea')
